package com.me.components {
	import com.me.components.fix.MapResourceProperty;
	import com.me.obj.Building;
	
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	import spark.core.SpriteVisualElement;
	import spark.filters.GlowFilter;

	/**
	 *
	 * @author yw
	 *
	 * @Date 2011-9-19 上午11:58:32
	 */
	public class MapResource extends SpriteVisualElement {

		protected var _fileName:String;

		private var _selected:Boolean;

		private var _attatchment:Building;

		public function MapResource() {
			super();
		}

		public function get fileName():String {
			return _fileName;
		}

		public function set selected(s:Boolean):void {
			_selected = s;
			if (s) {
				MapResourceProperty.getInstance().selectedResource = this;
				filters = [new GlowFilter(0x0664e3, 1, 4, 4, 16)];
			} else {
				filters = null;
			}
		}

		public function get selected():Boolean {
			return _selected;
		}

		public function get attatchment():Building {
			return _attatchment;
		}

		public function set attatchment(value:Building):void {
			_attatchment = value;
		}

		private function startDragHandler(e:MouseEvent):void {
			stage.addEventListener(MouseEvent.MOUSE_UP, stopDragHandler);
			startDrag(false, new Rectangle(0, 0, stage.stageWidth - width, stage.stageHeight - height));
		}

		private function stopDragHandler(e:MouseEvent):void {
			stopDrag();
			stage.removeEventListener(MouseEvent.MOUSE_UP, stopDragHandler);
		}

		public function dispose():void {
			while (numChildren > 0) {
				removeChildAt(0);
			}
			_attatchment = null;
		}
	}
}